//
//  JMGrabChipsCell.m
//  jiMuOperate
//
//  Created by 翁仪 on 16/5/4.
//  Copyright © 2016年 jinXinFengLi. All rights reserved.
//

#import "JMGrabChipsCell.h"
#import "robChipModel.h"
@implementation JMGrabChipsCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self createViews];
        [self setingDate];
        [self setingFrame];
    }
    return self;
}
-(void)createViews
{
    // 头部间隔视图
    UIView *headView = [[UIView alloc] init];
    [self.contentView addSubview:headView];
    self.headView = headView;
    // 姓名
    UILabel *nameLabel = [[UILabel alloc] init];
    [self.contentView addSubview:nameLabel];
    self.nameLabel = nameLabel;
//    [nameLabel setFont:[UIFont systemFontOfSize: 13]];
    // 等级
    UILabel *gradeLabel = [[UILabel alloc] init];
    [self.contentView addSubview:gradeLabel];
    self.gradeLabel = gradeLabel;

    // // 等级值
    UILabel *gradeNumLabel = [[UILabel alloc] init];
    [self.contentView addSubview:gradeNumLabel];
    self.gradeNumLabel = gradeNumLabel;
    self.gradeNumLabel.textColor = [UIColor redColor];

    //分隔视图
    UIView *padingView = [[UIView alloc] init];
    [self.contentView addSubview:padingView];
    self.padingView = padingView;

    // 胜率
    UILabel *winRateLabel = [[UILabel alloc] init];
    [self.contentView addSubview:winRateLabel];
    self.winRateLabel = winRateLabel;
    [winRateLabel setFont:[UIFont systemFontOfSize: 12]];
//    self.winRateLabel.textAlignment =NSTextAlignmentRight;
    // 胜率值
    UILabel *winRateNumLabel = [[UILabel alloc] init];
    [self.contentView addSubview:winRateNumLabel];
    self.winRateNumLabel = winRateNumLabel;
    [winRateNumLabel setFont:[UIFont systemFontOfSize: 18]];
    self.winRateNumLabel.textColor = [UIColor redColor];
    //计划编号
    UILabel *planNoLabel = [[UILabel alloc] init];
    [self.contentView addSubview:planNoLabel];
    self.planNoLabel = planNoLabel;
    [planNoLabel setFont:[UIFont systemFontOfSize: 11]];
    self.planNoLabel.textColor = RGB(165, 165, 165);
    //已投人数
    UILabel *pollYetLabel = [[UILabel alloc] init];
    [self.contentView addSubview:pollYetLabel];
    self.pollYetLabel = pollYetLabel;
    [pollYetLabel setFont:[UIFont systemFontOfSize: 11]];
    //已投人数zhi
    UILabel *PollYetNumLabel = [[UILabel alloc] init];
    [self.contentView addSubview:PollYetNumLabel];
    self.PollYetNumLabel = PollYetNumLabel;
    self.PollYetNumLabel.textColor = [UIColor redColor];
    self.PollYetNumLabel.textAlignment =NSTextAlignmentRight;
    [PollYetNumLabel setFont:[UIFont systemFontOfSize: 14]];
    //可投人数
    UILabel *PollPlanNumLabel = [[UILabel alloc] init];
    [self.contentView addSubview:PollPlanNumLabel];
    self.PollPlanNumLabel = PollPlanNumLabel;
    [PollPlanNumLabel setFont:[UIFont systemFontOfSize: 14]];
       // 进度条
    UIProgressView *progressView = [[UIProgressView alloc] init];
    [self.contentView addSubview:progressView];
    self.progressView  = progressView;

    // 立即投票按钮
    UIButton *voteBut = [[UIButton alloc] init];
    [self.contentView addSubview:voteBut];
    self.voteBut  = voteBut;
    voteBut.clipsToBounds = YES;
    voteBut.layer.cornerRadius = 3.f;//设置边角圆弧的半径，
    [voteBut setTitle:@"立即投票" forState:UIControlStateNormal];
    voteBut.titleLabel.font = [UIFont systemFontOfSize: 12];
    //分隔视图
    UIView *padingView1 = [[UIView alloc] init];
    [self.contentView addSubview:padingView1];
    self.padingView1 = padingView1;
//    padingView1.backgroundColor =[UIColor redColor];

}
-(void)setingDate{
    
//     姓名
    
    self.nameLabel.text = [NSString stringWithFormat:@"%@",_robChip.NickName];
    // 等级图片
    int number = _robChip.Level;
    self.gradeLabel.text = [NSString stringWithFormat:@"%d",number];
        [_gradeLabel setFont:[UIFont systemFontOfSize:12]];
    
    

    // 胜率
    self.winRateLabel.text =[NSString stringWithFormat:@"胜率"] ;
//    // 胜率值
    self.winRateNumLabel.text =[NSString stringWithFormat:@"%d",_robChip.WinRate] ;
    
    // 计划编码
//    self.planNoLabel.text =[NSString stringWithFormat:@"计划编码：%@",_robChip.StrategyNumber] ;
    

    //已投人数
    self.pollYetLabel.text =[NSString stringWithFormat:@"已投人数"] ;
    // 已投人数数量
    self.PollYetNumLabel.text =[NSString stringWithFormat:@"%d",_robChip.PollYet] ;
    // 可投人总数
    self.PollPlanNumLabel.text =[NSString stringWithFormat:@"/%d",_robChip.PollPlan] ;


    self.progressView.trackTintColor=RGB(218, 218, 218);
    //设置进度默认值，这个相当于百分比，范围在0~1之间，不可以设置最大最小值
    
    float floatString =_robChip.PollYet*0.01;
    self.progressView.progress=floatString;
    //设置进度条上进度的颜色
    self.progressView.progressTintColor=RGB(240, 174, 32);
    //设置进度值并动画显示
    [self.progressView setProgress:floatString animated:YES];
    
}
-(void)setingFrame{
      CGFloat cellH = 100;
      CGFloat padingH = 9;
      CGFloat padingW = 15;
//    cell的头部间隙
    CGFloat headViewX = 0;
    CGFloat headViewY = 0;
    CGFloat headViewW = 320;
    CGFloat headViewH = padingH;
    self.headView.frame = CGRectMake(headViewX, headViewY, headViewW, headViewH);
    self.headView.backgroundColor= RGB(238, 238, 238);
    
    // 设置Label的字体 HelveticaNeue  Courier
    UIFont *fnt = [UIFont fontWithName:@"HelveticaNeue" size:15.0f];
    _nameLabel.font = fnt;
    // 根据字体得到NSString的尺寸
//    CGSize size = [_nameLabel.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:fnt,NSFontAttributeName, nil]];
//    昵称
    CGFloat nameLabelX = padingW;
    CGFloat nameLabelY = headViewH;
    CGFloat nameLabelW = 90;
    CGFloat nameLabelH = 26;
//    self.nameLabel.backgroundColor= [UIColor yellowColor];
    self.nameLabel.frame = CGRectMake(nameLabelX, nameLabelY, nameLabelW, nameLabelH);
//等级图标
    CGFloat gradeImageX = nameLabelX+nameLabelW+20;
    CGFloat gradeImageY = nameLabelY;
    CGFloat gradeImageW = 90;
    CGFloat gradeImageH = nameLabelH;
    self.gradeLabel.frame = CGRectMake(gradeImageX, gradeImageY, gradeImageW, gradeImageH);
//    self.gradeLabel.backgroundColor= [UIColor redColor];

    CGFloat gradeNumLabelX = gradeImageX+gradeImageW;
    CGFloat gradeNumLabelY = nameLabelY;
    CGFloat gradeNumLabelW = 30;
    CGFloat gradeNumLabelH = nameLabelH;
    self.gradeNumLabel.frame = CGRectMake(gradeNumLabelX, gradeNumLabelY, gradeNumLabelW, gradeNumLabelH);
//    self.gradeNumLabel.backgroundColor= [UIColor yellowColor];
    //    胜率标签
    CGFloat winRateLabelW = 30;
    CGFloat winRateLabelX = 320-80;
    CGFloat winRateLabelY = nameLabelY;
    CGFloat winRateLabelH = nameLabelH;
//        self.winRateLabel.backgroundColor= [UIColor blueColor];
    self.winRateLabel.frame = CGRectMake(winRateLabelX, winRateLabelY, winRateLabelW, winRateLabelH);

//    胜率值
    CGFloat winRateNumLabelW = 48;
    CGFloat winRateNumLabelX = winRateLabelX+winRateLabelW;
    CGFloat winRateNumLabelY = winRateLabelY;
    CGFloat winRateNumLabelH = winRateLabelH;
//    self.winRateNumLabel.backgroundColor= [UIColor yellowColor];
    self.winRateNumLabel.frame = CGRectMake(winRateNumLabelX, winRateNumLabelY, winRateNumLabelW, winRateNumLabelH);
    //分割线
    CGFloat padingViewW = 320;
    CGFloat padingViewX = 0;
    CGFloat padingViewY = nameLabelY+nameLabelH+2;
    CGFloat padingViewH = 1;
    self.padingView.backgroundColor= RGB(238, 238, 238);

    self.padingView.frame = CGRectMake(padingViewX, padingViewY, padingViewW, padingViewH);
   //  计划编号
    CGFloat planNoLabelW = 320;
    CGFloat planNoLabelX = padingW;
    CGFloat planNoLabelY = padingViewY+padingViewH;
    CGFloat planNoLabelH = (cellH-padingViewY+padingViewH)/2;
//    self.planNoLabel.backgroundColor= [UIColor blueColor];
    self.planNoLabel.frame = CGRectMake(planNoLabelX, planNoLabelY, planNoLabelW, planNoLabelH);

    //    已投票数标签
    CGFloat pollYetLabelW = 50;
    CGFloat pollYetLabelX = padingW;
    CGFloat pollYetLabelH = planNoLabelH;
    CGFloat pollYetLabelY = cellH - pollYetLabelH-3;
//        self.pollYetLabel.backgroundColor= [UIColor blueColor];
    self.pollYetLabel.frame = CGRectMake(pollYetLabelX, pollYetLabelY, pollYetLabelW, pollYetLabelH);
    
//    已投票数量
    CGFloat PollYetNumLabelW = 30;
    CGFloat PollYetNumLabelX = pollYetLabelX+pollYetLabelW;
    CGFloat PollYetNumLabelY = pollYetLabelY;
    CGFloat PollYetNumLabelH = pollYetLabelH;
//    self.PollYetNumLabel.backgroundColor= [UIColor yellowColor];
    self.PollYetNumLabel.frame = CGRectMake(PollYetNumLabelX, PollYetNumLabelY, PollYetNumLabelW, PollYetNumLabelH);
//    计划投票数量
    CGFloat PollPlanNumLabelW = PollYetNumLabelW+10;
    CGFloat PollPlanNumLabelX = PollYetNumLabelX+PollYetNumLabelW;
    CGFloat PollPlanNumLabelY = PollYetNumLabelY;
    CGFloat PollPlanNumLabelH = PollYetNumLabelH;
//    self.PollPlanNumLabel.backgroundColor= [UIColor blueColor];
    self.PollPlanNumLabel.frame = CGRectMake(PollPlanNumLabelX, PollPlanNumLabelY, PollPlanNumLabelW, PollPlanNumLabelH);
//   进度条
    CGFloat progressViewW = 80;
    CGFloat progressViewH = 5;
    CGFloat progressViewX = PollPlanNumLabelX+PollPlanNumLabelW+padingW;
    CGFloat progressViewY = pollYetLabelY+PollPlanNumLabelH*0.5;
    self.progressView.frame = CGRectMake(progressViewX, progressViewY, progressViewW, progressViewH);
    self.progressView.backgroundColor= RGB(48, 183, 232);
    
//投票按钮
    CGFloat voteButW = 60;
    CGFloat voteButH = 23;
    CGFloat voteButX = 320-padingW-voteButW;
    CGFloat voteButY = padingViewY+(cellH-padingViewY-voteButH)/2;
    self.voteBut.frame = CGRectMake(voteButX, voteButY, voteButW, voteButH);
    self.voteBut.backgroundColor= RGB(225, 0, 26);
    //分割线
//    CGFloat padingViewW = 320;
//    CGFloat padingView1X = 0;
    CGFloat padingView1Y = cellH-1;
    CGFloat padingView1H = 1;
//    self.padingView1.backgroundColor= RGB(235, 235, 235);
    self.padingView1.frame = CGRectMake(padingViewX, padingView1Y, padingViewW, padingView1H);

        _voteBut.frame = [ToolViewAndData MyAutoLayoutOnlyWidth:_voteBut];
    _progressView.frame = [ToolViewAndData MyAutoLayoutOnlyWidth:_progressView];

    _PollPlanNumLabel.frame = [ToolViewAndData MyAutoLayoutOnlyWidth:_PollPlanNumLabel];
    _PollYetNumLabel.frame = [ToolViewAndData MyAutoLayoutOnlyWidth:_PollYetNumLabel];
    _pollYetLabel.frame = [ToolViewAndData MyAutoLayoutOnlyWidth:_pollYetLabel];
    _planNoLabel.frame = [ToolViewAndData MyAutoLayoutOnlyWidth:_planNoLabel];
    _padingView.frame = [ToolViewAndData MyAutoLayoutOnlyWidth:_padingView];
    _winRateNumLabel.frame = [ToolViewAndData MyAutoLayoutOnlyWidth:_winRateNumLabel];
    _winRateLabel.frame = [ToolViewAndData MyAutoLayoutOnlyWidth:_winRateLabel];
    _gradeLabel.frame = [ToolViewAndData MyAutoLayoutOnlyWidth:_gradeLabel];
    _nameLabel.frame = [ToolViewAndData MyAutoLayoutOnlyWidth:_nameLabel];
    _headView.frame = [ToolViewAndData MyAutoLayoutOnlyWidth:_headView];



}
@end
